//
//  TMWaveView.m
//  TMGold
//
//  Created by Mac on 2017/12/15.
//  Copyright © 2017年 tangmu. All rights reserved.
//

#import "TMWaveView.h"
#import "STWaveView.h"
@interface TMWaveView()
@property(nonatomic, strong) STWaveView                     *waveView;
@property(nonatomic, strong) UIView                     *backView;
@end
@implementation TMWaveView

- (instancetype)initWithFrame:(CGRect)frame waveTopColor:(UIColor *)waveTopColor waveBootomColor:(UIColor *)waveBootomColor title:(NSString *)title titleColor:(UIColor *)titleColor persent:(CGFloat)persent{
    if (self == [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor ];
        self.titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, self.width, 20)
                                                         text:title
                                                    textColor:titleColor
                                                         font:14
                                                  isSizetoFit:NO
                                                textAlignment:NSTextAlignmentCenter];
        [self addSubview:self.titleLable];
        self.titleLable.bottom = self.height;
        
        UIView * backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height - 20 )];
        backView.backgroundColor = [UIColor whiteColor];
        backView.clipsToBounds = YES;
        [self addSubview:backView];
        backView.userInteractionEnabled = NO;
        self.backView = backView;
        
        self.waveView = [[STWaveView alloc] initWithFrame:CGRectMake(0, 10, backView.height - 20, backView.height - 20)];
        self.waveView.clipsToBounds = YES;
        self.waveView.backgroundColor = [UIColor whiteColor];
        self.waveView.layer.cornerRadius = self.waveView.height / 2;
//        [self.waveView st_setBrderWidth:0.5 borderColor:FlatWhiteDark];
        self.waveView.centerX = self.width / 2;
        self.waveView.present = persent;
        self.waveView.size = CGSizeMake(0, 0);
        self.waveView.wavePresent = 0.6;
        self.waveView.waveTopColor = waveTopColor;
        self.waveView.waveBootomColor = waveBootomColor;
        [backView addSubview:self.waveView];
    }
    return self;
}
- (void)beginAnimation{
    [UIView animateWithDuration:0.25 delay:0 usingSpringWithDamping:0.75 initialSpringVelocity:0.84 options:UIViewAnimationOptionTransitionNone animations:^{
        
        self.waveView.frame = CGRectMake(0, 10, _backView.height - 20, _backView.height - 20);
        self.waveView.centerX = self.width / 2;
        self.waveView.layer.cornerRadius = self.waveView.height / 2;
        
    } completion:^(BOOL finished) {
        
    }];
}
- (void)setWavePresent:(CGFloat)wavePresent{
    if (wavePresent == 0) {
        wavePresent = 0.05;
    }
    _wavePresent = wavePresent;
    self.waveView.present = wavePresent;
}
@end
